<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Short Examples for the Impatient</title>
<link rel="stylesheet" href="../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset">
<link rel="up" href="../boost_pfr.html" title="Chapter 26. Boost.PFR 2.3">
<link rel="prev" href="../boost_pfr.html" title="Chapter 26. Boost.PFR 2.3">
<link rel="next" href="tutorial.html" title="Tutorial">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../boost.png"></td>
<td align="center"><a href="../../../index.html">Home</a></td>
<td align="center"><a href="../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../boost_pfr.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../boost_pfr.html"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="tutorial.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="boost_pfr.short_examples_for_the_impatient"></a><a class="link" href="short_examples_for_the_impatient.html" title="Short Examples for the Impatient">Short Examples
    for the Impatient</a>
</h2></div></div></div>
<div class="informaltable">
<a name="boost_pfr.short_examples_for_the_impatient.quick_examples"></a><table class="table">
<colgroup>
<col>
<col>
</colgroup>
<thead><tr>
<th>
              <p>
                Code snippet
              </p>
            </th>
<th>
              <p>
                Reference:
              </p>
            </th>
</tr></thead>
<tbody>
<tr>
<td>
<pre class="table-programlisting"><span class="comment">// Get field by index/type and assign new value to that field</span>

<span class="keyword">struct</span> <span class="identifier">sample</span> <span class="special">{</span>
    <span class="keyword">char</span> <span class="identifier">c</span><span class="special">;</span>
    <span class="keyword">float</span> <span class="identifier">f</span><span class="special">;</span>
<span class="special">};</span>

<span class="identifier">sample</span> <span class="identifier">var</span><span class="special">{};</span>
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">pfr</span><span class="special">::</span><span class="identifier">get</span><span class="special">&lt;</span><span class="number">1</span><span class="special">&gt;(</span><span class="identifier">var</span><span class="special">)</span> <span class="special">=</span> <span class="number">42.01f</span><span class="special">;</span>
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">pfr</span><span class="special">::</span><span class="identifier">get</span><span class="special">&lt;</span><span class="keyword">char</span><span class="special">&gt;(</span><span class="identifier">var</span><span class="special">)</span> <span class="special">=</span> <span class="char">'A'</span><span class="special">;</span>

<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">var</span><span class="special">.</span><span class="identifier">c</span> <span class="special">&lt;&lt;</span> <span class="identifier">var</span><span class="special">.</span><span class="identifier">f</span><span class="special">;</span> <span class="comment">// Outputs: A 42.01</span>
</pre>
            </td>
<td>
              <p>
                <code class="computeroutput"><a class="link" href="../doxygen/reference_section_of_pfr/core_8hpp_1a07b17ed2eaa9115346f5b14899ec53e4.html" title="Function template get">boost::pfr::get</a></code>
              </p>
            </td>
</tr>
<tr>
<td>
<pre class="table-programlisting"><span class="comment">// Get name of field by index</span>

<span class="keyword">struct</span> <span class="identifier">sample</span> <span class="special">{</span>
    <span class="keyword">int</span> <span class="identifier">f_int</span><span class="special">;</span>
    <span class="keyword">long</span> <span class="identifier">f_long</span><span class="special">;</span>
<span class="special">};</span>

<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">pfr</span><span class="special">::</span><span class="identifier">get_name</span><span class="special">&lt;</span><span class="number">0</span><span class="special">,</span> <span class="identifier">sample</span><span class="special">&gt;()</span>
          <span class="special">&lt;&lt;</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">pfr</span><span class="special">::</span><span class="identifier">get_name</span><span class="special">&lt;</span><span class="number">1</span><span class="special">,</span> <span class="identifier">sample</span><span class="special">&gt;();</span> <span class="comment">// Outputs: f_int f_long</span>
</pre>
            </td>
<td>
              <p>
                <code class="computeroutput"><a class="link" href="../doxygen/reference_section_of_pfr/core__name_8hpp_1ad820b865b5817b15c21faca3f470e511.html" title="Function template get_name">boost::pfr::get_name</a></code>
              </p>
            </td>
</tr>
<tr>
<td>
<pre class="table-programlisting"><span class="comment">// Assert equality.</span>
<span class="comment">// Note that the equality operator for structure is not defined.</span>

<span class="keyword">struct</span> <span class="identifier">test</span> <span class="special">{</span>
    <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="identifier">f1</span><span class="special">;</span>
    <span class="identifier">std</span><span class="special">::</span><span class="identifier">string_view</span> <span class="identifier">f2</span><span class="special">;</span>
<span class="special">};</span>

<span class="identifier">assert</span><span class="special">(</span>
    <span class="identifier">boost</span><span class="special">::</span><span class="identifier">pfr</span><span class="special">::</span><span class="identifier">eq</span><span class="special">(</span><span class="identifier">test</span><span class="special">{</span><span class="string">"aaa"</span><span class="special">,</span> <span class="string">"zomg"</span><span class="special">},</span> <span class="identifier">test</span><span class="special">{</span><span class="string">"aaa"</span><span class="special">,</span> <span class="string">"zomg"</span><span class="special">})</span>
<span class="special">);</span>
</pre>
            </td>
<td>
              <p>
                <code class="computeroutput"><a class="link" href="../reference_section_of_pfr.html#doxygen.reference_section_of_pfr.ops_8hpp" title="Header &lt;boost/pfr/ops.hpp&gt;">Header boost/pfr/ops.hpp</a></code>:
              </p>
              <p>
                * <code class="computeroutput"><a class="link" href="../doxygen/reference_section_of_pfr/ops_8hpp_1a8d231fd562e78a07a9942d6b55fa9e16.html" title="Function template eq">boost::pfr::eq</a></code>
              </p>
              <p>
                * <code class="computeroutput"><a class="link" href="../doxygen/reference_section_of_pfr/ops_8hpp_1a952c8fa2656fc8479162dd3dc91652c8.html" title="Function template ne">boost::pfr::ne</a></code>
              </p>
              <p>
                * <code class="computeroutput"><a class="link" href="../doxygen/reference_section_of_pfr/ops_8hpp_1a7d148d33a99eff5423d53287bba132ce.html" title="Function template gt">boost::pfr::gt</a></code>
              </p>
              <p>
                * ...
              </p>
            </td>
</tr>
<tr>
<td>
<pre class="table-programlisting"><span class="comment">// Increment each field of the variable on 1 and</span>
<span class="comment">// output the content of the variable.</span>

<span class="keyword">struct</span> <span class="identifier">test</span> <span class="special">{</span>
    <span class="keyword">int</span> <span class="identifier">f1</span><span class="special">;</span>
    <span class="keyword">long</span> <span class="identifier">f2</span><span class="special">;</span>
<span class="special">};</span>

<span class="identifier">test</span> <span class="identifier">var</span><span class="special">{</span><span class="number">42</span><span class="special">,</span> <span class="number">43</span><span class="special">};</span>

<span class="identifier">boost</span><span class="special">::</span><span class="identifier">pfr</span><span class="special">::</span><span class="identifier">for_each_field</span><span class="special">(</span><span class="identifier">var</span><span class="special">,</span> <span class="special">[](</span><span class="keyword">auto</span><span class="special">&amp;</span> <span class="identifier">field</span><span class="special">)</span> <span class="special">{</span>
    <span class="identifier">field</span> <span class="special">+=</span> <span class="number">1</span><span class="special">;</span>
<span class="special">});</span>

<span class="comment">// Outputs: {43, 44}</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">pfr</span><span class="special">::</span><span class="identifier">io</span><span class="special">(</span><span class="identifier">var</span><span class="special">);</span>
</pre>
            </td>
<td>
              <p>
                <code class="computeroutput">boost::pfr::for_each_field</code>
              </p>
              <p>
                <code class="computeroutput"><a class="link" href="../doxygen/reference_section_of_pfr/io_8hpp_1adcb0ad73dc25ac01d68cf0e7fb98d506.html" title="Function template io">boost::pfr::io</a></code>
              </p>
            </td>
</tr>
<tr>
<td>
<pre class="table-programlisting"><span class="comment">// Print the name and value</span>
<span class="comment">// of each element of the structure</span>

<span class="keyword">struct</span> <span class="identifier">test</span> <span class="special">{</span>
    <span class="keyword">int</span> <span class="identifier">n</span><span class="special">;</span>
    <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="identifier">str</span><span class="special">;</span>
<span class="special">};</span>

<span class="identifier">test</span> <span class="identifier">var</span><span class="special">{</span><span class="number">42</span><span class="special">,</span> <span class="string">"Hello, World!"</span><span class="special">};</span>

<span class="comment">// Outputs:</span>
<span class="comment">//  n: 42</span>
<span class="comment">//  str: Hello, World!</span>
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">pfr</span><span class="special">::</span><span class="identifier">for_each_field_with_name</span><span class="special">(</span><span class="identifier">var</span><span class="special">,</span>
  <span class="special">[](</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">string_view</span> <span class="identifier">name</span><span class="special">,</span> <span class="keyword">const</span> <span class="keyword">auto</span><span class="special">&amp;</span> <span class="identifier">value</span><span class="special">)</span> <span class="special">{</span>
    <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">name</span> <span class="special">&lt;&lt;</span> <span class="string">": "</span> <span class="special">&lt;&lt;</span> <span class="identifier">value</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
<span class="special">});</span>
</pre>
            </td>
<td>
              <p>
                <code class="computeroutput"><a class="link" href="../doxygen/reference_section_of_pfr/core__name_8hpp_1a8c6c718187b9f6e884e6fc9f53c5d7e6.html" title="Function template for_each_field_with_name">boost::pfr::for_each_field_with_name</a></code>
              </p>
            </td>
</tr>
<tr>
<td>
<pre class="table-programlisting"><span class="comment">// Define all the comparison and IO operators for my_structure type along</span>
<span class="comment">// with hash_value function.</span>

<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">pfr</span><span class="special">/</span><span class="identifier">functions_for</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>

<span class="keyword">namespace</span> <span class="identifier">my_namespace</span> <span class="special">{</span>
    <span class="keyword">struct</span> <span class="identifier">my_structure</span> <span class="special">{</span>
        <span class="keyword">int</span> <span class="identifier">a</span><span class="special">,</span><span class="identifier">b</span><span class="special">,</span><span class="identifier">c</span><span class="special">,</span><span class="identifier">d</span><span class="special">,</span><span class="identifier">e</span><span class="special">,</span><span class="identifier">f</span><span class="special">,</span><span class="identifier">g</span><span class="special">;</span>
        <span class="comment">// ...</span>
    <span class="special">};</span>
    <span class="identifier">BOOST_PFR_FUNCTIONS_FOR</span><span class="special">(</span><span class="identifier">my_structure</span><span class="special">)</span>
<span class="special">}</span>
</pre>
            </td>
<td>
              <p>
                <code class="computeroutput"><a class="link" href="../doxygen/reference_section_of_pfr/functions__for_8hpp_1a4092167ce3b09df7a69fe9123cf48c6a.html" title="Macro BOOST_PFR_FUNCTIONS_FOR">BOOST_PFR_FUNCTIONS_FOR</a></code>
              </p>
            </td>
</tr>
<tr>
<td>
<pre class="table-programlisting"><span class="comment">// Define only the equality and inequality operators for my_eq_ne_structure.</span>

<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">pfr</span><span class="special">/</span><span class="identifier">functions_for</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>

<span class="keyword">namespace</span> <span class="identifier">my_namespace</span> <span class="special">{</span>
    <span class="keyword">struct</span> <span class="identifier">my_eq_ne_structure</span> <span class="special">{</span>
        <span class="keyword">float</span> <span class="identifier">a</span><span class="special">,</span><span class="identifier">b</span><span class="special">,</span><span class="identifier">c</span><span class="special">,</span><span class="identifier">d</span><span class="special">,</span><span class="identifier">e</span><span class="special">,</span><span class="identifier">f</span><span class="special">,</span><span class="identifier">g</span><span class="special">;</span>
        <span class="comment">// ...</span>
    <span class="special">};</span>

    <span class="keyword">inline</span> <span class="keyword">bool</span> <span class="keyword">operator</span><span class="special">==(</span><span class="keyword">const</span> <span class="identifier">my_eq_ne_structure</span><span class="special">&amp;</span> <span class="identifier">x</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">my_eq_ne_structure</span><span class="special">&amp;</span> <span class="identifier">y</span><span class="special">)</span> <span class="special">{</span>
        <span class="keyword">return</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">pfr</span><span class="special">::</span><span class="identifier">eq_fields</span><span class="special">(</span><span class="identifier">x</span><span class="special">,</span> <span class="identifier">y</span><span class="special">);</span>
    <span class="special">}</span>

    <span class="keyword">inline</span> <span class="keyword">bool</span> <span class="keyword">operator</span><span class="special">!=(</span><span class="keyword">const</span> <span class="identifier">my_eq_ne_structure</span><span class="special">&amp;</span> <span class="identifier">x</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">my_eq_ne_structure</span><span class="special">&amp;</span> <span class="identifier">y</span><span class="special">)</span> <span class="special">{</span>
        <span class="keyword">return</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">pfr</span><span class="special">::</span><span class="identifier">ne_fields</span><span class="special">(</span><span class="identifier">x</span><span class="special">,</span> <span class="identifier">y</span><span class="special">);</span>
    <span class="special">}</span>
<span class="special">}</span>
</pre>
            </td>
<td>
              <p>
                <code class="computeroutput"><a class="link" href="../reference_section_of_pfr.html#doxygen.reference_section_of_pfr.ops__fields_8hpp" title="Header &lt;boost/pfr/ops_fields.hpp&gt;">Header boost/pfr/ops_fields.hpp
                </a></code>:
              </p>
              <p>
                * <code class="computeroutput"><a class="link" href="../doxygen/reference_section_of_pfr/ops__fields_8hpp_1a0296971dd9810d022b3b8ec7f43cbaed.html" title="Function template eq_fields">boost::pfr::eq_fields</a></code>
              </p>
              <p>
                * <code class="computeroutput"><a class="link" href="../doxygen/reference_section_of_pfr/ops__fields_8hpp_1affccfae701ea29ddf4debeeab7a00291.html" title="Function template ne_fields">boost::pfr::ne_fields</a></code>
              </p>
              <p>
                * <code class="computeroutput"><a class="link" href="../doxygen/reference_section_of_pfr/ops__fields_8hpp_1a233391590dbd80765626d44295a7beb5.html" title="Function template gt_fields">boost::pfr::gt_fields</a></code>
              </p>
              <p>
                * ...
              </p>
              <p>
                <code class="computeroutput"><a class="link" href="../reference_section_of_pfr.html#doxygen.reference_section_of_pfr.io__fields_8hpp" title="Header &lt;boost/pfr/io_fields.hpp&gt;">Header boost/pfr/io_fields.hpp
                </a></code>
              </p>
              <p>
                * <code class="computeroutput"><a class="link" href="../doxygen/reference_section_of_pfr/io__fields_8hpp_1a443c5a5adc536e5a94c732f76c673d20.html" title="Function template io_fields">boost::pfr::io_fields</a></code>
              </p>
            </td>
</tr>
<tr>
<td>
<pre class="table-programlisting"><span class="comment">// Iterate over fields of a variable and output index and</span>
<span class="comment">// type of a variable.</span>

<span class="keyword">struct</span> <span class="identifier">tag0</span><span class="special">{};</span>
<span class="keyword">struct</span> <span class="identifier">tag1</span><span class="special">{};</span>
<span class="keyword">struct</span> <span class="identifier">sample</span> <span class="special">{</span>
    <span class="identifier">tag0</span> <span class="identifier">a</span><span class="special">;</span>
    <span class="identifier">tag1</span> <span class="identifier">b</span><span class="special">;</span>
<span class="special">};</span>

<span class="comment">// Outputs:</span>
<span class="comment">//  0: tag0</span>
<span class="comment">//  1: tag1</span>
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">pfr</span><span class="special">::</span><span class="identifier">for_each_field</span><span class="special">(</span><span class="identifier">sample</span><span class="special">{},</span> <span class="special">[](</span><span class="keyword">const</span> <span class="keyword">auto</span><span class="special">&amp;</span> <span class="identifier">field</span><span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">idx</span><span class="special">)</span> <span class="special">{</span>
    <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="char">'\n'</span> <span class="special">&lt;&lt;</span> <span class="identifier">idx</span> <span class="special">&lt;&lt;</span> <span class="string">": "</span>
        <span class="special">&lt;&lt;</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">typeindex</span><span class="special">::</span><span class="identifier">type_id_runtime</span><span class="special">(</span><span class="identifier">field</span><span class="special">);</span>
<span class="special">});</span>
</pre>
            </td>
<td>
              <p>
                <code class="computeroutput">boost::pfr::for_each_field</code>
              </p>
            </td>
</tr>
<tr>
<td>
<pre class="table-programlisting"><span class="comment">// Getting fields count of some structure</span>

<span class="keyword">struct</span> <span class="identifier">some</span> <span class="special">{</span> <span class="keyword">int</span> <span class="identifier">a</span><span class="special">,</span><span class="identifier">b</span><span class="special">,</span><span class="identifier">c</span><span class="special">,</span><span class="identifier">d</span><span class="special">,</span><span class="identifier">e</span><span class="special">;</span> <span class="special">};</span>

<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="string">"Fields count in structure: "</span>
    <span class="special">&lt;&lt;</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">pfr</span><span class="special">::</span><span class="identifier">tuple_size</span><span class="special">&lt;</span><span class="identifier">some</span><span class="special">&gt;::</span><span class="identifier">value</span>  <span class="comment">// Outputs: 5</span>
    <span class="special">&lt;&lt;</span> <span class="char">'\n'</span><span class="special">;</span>
</pre>
            </td>
<td>
              <p>
                <code class="computeroutput"><a class="link" href="../doxygen/reference_section_of_pfr/tuple__size_8hpp_1afd9406c04ab356128728739825f6e770.html" title="Type definition tuple_size">boost::pfr::tuple_size</a></code>
              </p>
            </td>
</tr>
<tr>
<td>
<pre class="table-programlisting"><span class="comment">// Getting a std::tuple of values from structures fields</span>

<span class="keyword">struct</span> <span class="identifier">foo</span> <span class="special">{</span> <span class="keyword">int</span> <span class="identifier">a</span><span class="special">,</span> <span class="identifier">b</span><span class="special">;</span> <span class="special">};</span>
<span class="keyword">struct</span> <span class="identifier">other</span> <span class="special">{</span>
    <span class="keyword">char</span> <span class="identifier">c</span><span class="special">;</span>
    <span class="identifier">foo</span> <span class="identifier">nested</span><span class="special">;</span>
<span class="special">};</span>

<span class="identifier">other</span> <span class="identifier">var</span><span class="special">{</span><span class="char">'A'</span><span class="special">,</span> <span class="special">{</span><span class="number">3</span><span class="special">,</span> <span class="number">4</span><span class="special">}};</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">tuple</span><span class="special">&lt;</span><span class="keyword">char</span><span class="special">,</span> <span class="identifier">foo</span><span class="special">&gt;</span> <span class="identifier">t</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">pfr</span><span class="special">::</span><span class="identifier">structure_to_tuple</span><span class="special">(</span><span class="identifier">var</span><span class="special">);</span>
<span class="identifier">assert</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">get</span><span class="special">&lt;</span><span class="number">0</span><span class="special">&gt;(</span><span class="identifier">t</span><span class="special">)</span> <span class="special">==</span> <span class="char">'A'</span><span class="special">);</span>
<span class="identifier">assert</span><span class="special">(</span>
    <span class="identifier">boost</span><span class="special">::</span><span class="identifier">pfr</span><span class="special">::</span><span class="identifier">eq</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">get</span><span class="special">&lt;</span><span class="number">1</span><span class="special">&gt;(</span><span class="identifier">t</span><span class="special">),</span> <span class="identifier">foo</span><span class="special">{</span><span class="number">3</span><span class="special">,</span> <span class="number">4</span><span class="special">})</span>
<span class="special">);</span>
</pre>
            </td>
<td>
              <p>
                <code class="computeroutput"><a class="link" href="../doxygen/reference_section_of_pfr/core_8hpp_1afa68927e3e0e191200fad450e79bb389.html" title="Function template structure_to_tuple">boost::pfr::structure_to_tuple</a></code>
              </p>
            </td>
</tr>
<tr>
<td>
<pre class="table-programlisting"><span class="comment">// Getting a std::tuple of references to structure fields</span>

<span class="keyword">struct</span> <span class="identifier">foo</span> <span class="special">{</span> <span class="keyword">int</span> <span class="identifier">a</span><span class="special">,</span> <span class="identifier">b</span><span class="special">;</span> <span class="special">};</span>
<span class="keyword">struct</span> <span class="identifier">other</span> <span class="special">{</span>
    <span class="keyword">char</span> <span class="identifier">c</span><span class="special">;</span>
    <span class="identifier">foo</span> <span class="identifier">f</span><span class="special">;</span>
<span class="special">};</span>

<span class="identifier">other</span> <span class="identifier">var</span><span class="special">{</span><span class="char">'A'</span><span class="special">,</span> <span class="special">{</span><span class="number">14</span><span class="special">,</span> <span class="number">15</span><span class="special">}};</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">tuple</span><span class="special">&lt;</span><span class="keyword">char</span><span class="special">&amp;,</span> <span class="identifier">foo</span><span class="special">&amp;&gt;</span> <span class="identifier">t</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">pfr</span><span class="special">::</span><span class="identifier">structure_tie</span><span class="special">(</span><span class="identifier">var</span><span class="special">);</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">get</span><span class="special">&lt;</span><span class="number">1</span><span class="special">&gt;(</span><span class="identifier">t</span><span class="special">)</span> <span class="special">=</span> <span class="identifier">foo</span><span class="special">{</span><span class="number">1</span><span class="special">,</span> <span class="number">2</span><span class="special">};</span>

<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">pfr</span><span class="special">::</span><span class="identifier">io</span><span class="special">(</span><span class="identifier">var</span><span class="special">.</span><span class="identifier">f</span><span class="special">);</span> <span class="comment">// Outputs: {1, 2}</span>
</pre>
            </td>
<td>
              <p>
                <code class="computeroutput">boost::pfr::structure_tie</code>
              </p>
            </td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="copyright-footer">Copyright © 2016-2025 Antony Polukhin<p>
        Distributed under the Boost Software License, Version 1.0. (See accompanying
        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
      </p>
</div>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../boost_pfr.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../boost_pfr.html"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="tutorial.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
